package com.ys.web.sys.notice.controller;

import com.ys.base.BaseConstants;
import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.JsonUtil;
import com.ys.web.sys.notice.po.SystemNoticePo;
import com.ys.web.sys.notice.service.NoticeService;
import com.ys.web.sys.notice.vo.SystemNoticeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author quxinjun
 * @version 1.0.0
 * @ClassName NoticeController.java
 * @Description TODO
 * @createTime 2021年11月01日 14:04:00
 */
@Slf4j
@RestController
@RequestMapping("/sys/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;


    @PostMapping("/list")
    public String list(String ids) {
        List<SystemNoticePo> result = noticeService.getSystemNoticeList(ids);
        return ResponseHandler.list(result);
    }

    @PostMapping("/addNotice")
    public String addNotice(@RequestAttribute Long uid, SystemNoticeVo systemNoticeVo) {
        systemNoticeVo.checkParam();
        systemNoticeVo.setUserId(uid);
        noticeService.addNotice(systemNoticeVo);
        return ResponseHandler.success();
    }

    @PostMapping("/background/addNotice")
    public String backgroundAddNotice(@RequestBody String param) {
        SystemNoticeVo obj = JsonUtil.jsonToBean(param, SystemNoticeVo.class);
        obj.checkParam();
        obj.setUserId(BaseConstants.ClientConstants.CLIENT_ID);
        noticeService.addNotice(obj);
        return ResponseHandler.success();
    }
    @PostMapping("/background/user/addNotice")
    public String backgroundUserAddNotice(@RequestBody String param) {
        SystemNoticeVo obj = JsonUtil.jsonToBean(param, SystemNoticeVo.class);
        obj.checkParam();
        obj.setUserId(BaseConstants.ClientConstants.CLIENT_ID);
        noticeService.backgroundUserAddNotice(obj);
        return ResponseHandler.success();
    }

}
